package com.haizhi.crm.sys.auth.dao;

import com.haizhi.crm.sys.auth.model.RelationRoleDo;
import com.haizhi.crm.sys.auth.model.RelationRoleVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yangyijun on 2018/5/21.
 */
@Repository
public interface RelationRoleDao extends JpaRepository<RelationRoleDo, Long> {
    List<RelationRoleDo> findByRelationId(@Param("relationId" ) Long relationId);

    @Query(value = "select new com.haizhi.crm.sys.auth.model.RelationRoleVo" +
            "(r.id,r.name,rr.relationFileName,rr.relationFileUrl,rr.updatedDt) " +
            "from RelationDo r,RelationRoleDo rr " +
            "where r.id=rr.relationId" )
    List<RelationRoleVo> list();

    @Query(value = "select new com.haizhi.crm.sys.auth.model.RelationRoleVo" +
            "(r.id,r.name,rr.relationFileName,rr.relationFileUrl,rr.updatedDt) " +
            "from RelationDo r,RelationRoleDo rr " +
            "where r.id=rr.relationId and r.id=:relationId" )
    List<RelationRoleVo> findBy(@Param("relationId" ) Long relationId);
}
